/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bungabungaball.player;

import bungabungaball.GlobalSettings;
import bungabungaball.PlayerControl;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;

/**
 * A Player that is controlled by a human player.
 * 
 * @author Ingo Klose, Stephan Meyer, Sebastian Lehmann
 * @version 1.0
 */
public class Human extends Player {

    /**
     * Constructor
     * @param x
     * @param y
     * @param image
     * @param w
     */
    public Human(int x, int y, Image image, World w) {
        super(x, y, image, w);
        init();
    }

    /**
     * Constructor
     * @param x
     * @param y
     * @param image
     */
    public Human(int x, int y, Image image) {
        super(x, y, image);
        init();
    }

    /**
     * Constructor
     * @param x
     * @param y
     */
    public Human(int x, int y) {
        super(x, y);
        init();
    }

    /**
     * Constructor
     * @param image
     */
    public Human(Image image) {
        super(image);
        init();
    }

    /**
     * Constructor
     */
    public Human() {
        super();
        init();
    }

    /**
     * draw the player
     * @param g
     */
    @Override
    public void draw(Graphics g) {
        g.drawImage(image, x, y);
    }

    /**
     * Move the player
     * @param pc
     * @param delta
     * @param body
     * @param keyMapClientPlayer 
     */
    @Override
    public void move(PlayerControl pc, int delta, Body body, boolean[] keyMapClientPlayer) {

        GameContainer gc = pc.gameContainer;
        Input input = gc.getInput();

        if (input.isKeyDown(keyMap[0])) {
            this.rotate(-this.rotation * delta);
        }
        if (input.isKeyDown(keyMap[1])) {
            this.rotate(this.rotation * delta);
        }
        if (!input.isKeyDown(keyMap[2]) && !input.isKeyDown(keyMap[3])) {
            makeFriction(body);
        }
        if (input.isKeyDown(keyMap[2])) {
            float hip = this.speed * delta;
            double speedRotation = Math.toRadians(this.getRotation() - 90.f);
            Vec2 force = new Vec2((float) (hip * Math.cos(speedRotation)), (float) (hip * Math.sin(speedRotation)));

            if(controlMode == GlobalSettings.ControlMode.Normal)
                body.setLinearVelocity(force);
            else
                body.applyLinearImpulse(force, body.getWorldCenter());
                
        }
        if (input.isKeyDown(keyMap[3])) {
            float hip = this.speed * delta;
            double speedRotation = Math.toRadians(this.getRotation() - 90.f);
            Vec2 force = new Vec2(-(float) (hip * Math.cos(speedRotation)), -(float) (hip * Math.sin(speedRotation)));
            
            if(controlMode == GlobalSettings.ControlMode.Normal)
                body.setLinearVelocity(force);
            else
                body.applyLinearImpulse(force, body.getWorldCenter());
        }

    }
}
